
import { Controller, Get, Post, Put, Body, Query, Param, Delete } from '@nestjs/common';
import { ApiTags, ApiOperation } from '@nestjs/swagger';
import { RequirePermission } from 'src/common/decorators/require-premission.decorator';
import { ProfessionalService } from './professional.service';
import { CreateProfessionalDto, BaseProfessionalDto, UpdateProfessionalDto, QueryProfessionalDto, ListProfessionalDto } from './dto/professional.dto';
import { ApiDataResponse } from 'src/common/decorators/apiDataResponse.decorator';
import { UserTool, UserToolType } from 'src/module/system/user/user.decorator';
import { RepeatSubmit } from 'src/common/decorators/repeat-submit.decorator';
import {BusinessType} from "../../../common/constant/business.constant";
import {Operlog} from "../../../common/decorators/operlog.decorator";

@ApiTags('专业管理')
@Controller('edutation/professional')
export class ProfessionalController {
constructor(private readonly professionalService: ProfessionalService) {}
    @ApiOperation({ summary: '专业管理-创建',  })
    @ApiDataResponse(BaseProfessionalDto)
    @RequirePermission('edutation:professional:add')
    @Post()
    @RepeatSubmit()
    @Operlog({ businessType: BusinessType.UPDATE })
    create(@Body() body: CreateProfessionalDto,@UserTool() { injectCreate }: UserToolType) {
        return this.professionalService.create(injectCreate(body));
    }


    @ApiOperation({ summary: '专业管理-列表',  })
    @ApiDataResponse(ListProfessionalDto, true, true)
    @RequirePermission('edutation:professional:list')
    @Get('list')
    findAll(@Query() query: QueryProfessionalDto) {
        return this.professionalService.findAll(query);
    }


    @ApiOperation({  summary: '专业管理-详情',    })
    @ApiDataResponse(BaseProfessionalDto)
    @RequirePermission('edutation:professional:query')
    @Get(':id')
    findOne(@Param('id') id: string) {
        return this.professionalService.findOne(+id);
    }


    @ApiOperation({ summary: '专业管理-修改',  })
    @ApiDataResponse()
    @RequirePermission('edutation:professional:edit')
    @Put()
    @RepeatSubmit()
    @Operlog({ businessType: BusinessType.UPDATE })
    update(@Body() body: UpdateProfessionalDto,@UserTool() { injectUpdate }: UserToolType) {
        return this.professionalService.update(injectUpdate(body));
    }


    @ApiOperation({  summary: '专业管理-删除', })
    @ApiDataResponse()
    @RequirePermission('edutation:professional:remove')
    @Delete(':ids')
    @Operlog({ businessType: BusinessType.DELETE })
    remove(@Param('ids') ids: string) {
        const proIdList = ids.split(',').map((id) => +id);
        return this.professionalService.remove(proIdList);
    }



}
